const MD5 = require("../assets/js/md5.min.js")

const key = '2vlndQ1ak2BqHDY7Q1UVjhOtjcQpXd90'

export default function md5(data) {
  let tempSign = ''
  const postData = JSON.stringify(data)
  const keyList = Object.keys(data)
  const valueList = Object.values(data)
  let temp = keyList.map((item, index) => {
    if (index === keyList.length - 1) {
      return `${item}=${valueList[index]}`
    } else {
      return `${item}=${valueList[index]}&`
    }
  })

  for (let item of temp) {
    tempSign += item
  }

  let rs = MD5(MD5(tempSign) + key)

  return {
    sign: rs,
    data: postData
  }
}
